package com.kkb.projectauth.service.impl;

import com.kkb.projectauth.dao.UserDao;
import com.kkb.projectauth.dao.UserInfoDao;
import com.kkb.projectauth.dto.UserInfoParam;
import com.kkb.projectauth.dto.UserUpdateParam;
import com.kkb.projectauth.pojo.User;
import com.kkb.projectauth.pojo.UserInfo;
import com.kkb.projectauth.service.UserInfoService;
import com.kkb.projectcommon.api.CommonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author: 黄小帅
 * @date: 2021/4/16 20:31
 **/
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    private UserInfoDao userInfoDao;

    @Resource
    private UserDao userDao;

    /**
     * 通过用户ID查找用户的个人信息
     * @param id
     * @return
     */
    @Override
    public HashMap<String,String> getUserInfo(Long id) {
        HashMap<String,String> hashMap = new HashMap<>(3);
        try {
            UserInfo userInfo = userInfoDao.selectById(id);
            String phone = userInfo.getPhone();
            User user = userDao.selectById(id);
            String wx_card = user.getWxCard();
            String name = user.getName();

            hashMap.put("phone", phone);
            hashMap.put("wx_card", wx_card);
            hashMap.put("name", name);
        } catch (Exception e) {
            // CommonResult.failed("获取信息失败，用户不存在")
            return null;
        }
        // CommonResult.success(hashMap,"获取信息成功")
        return hashMap;
    }

    /**
     * 通过用户ID查找用户的个人信息
     * @param id
     * @return
     */
    @Override
    public HashMap<String,String> getUserICon(Long id) {
        HashMap<String,String> hashMap = new HashMap<>(1);
        try {
            User user = userDao.selectById(id);
            String iconUrl = user.getImageHard();
            hashMap.put("image_hard", iconUrl);
        } catch (Exception e) {
            return null;
        }
        return hashMap;
    }
}
